// DirWatcher.h: interface for the DirWatcher class.
//
//////////////////////////////////////////////////////////////////////

#ifndef _DIRWATCHER_H_
#define _DIRWATCHER_H_


#include "monitorinterface.h"
#include <Windows.h>
#include <tchar.h>
#include "DirectoryWatcher.h"

struct DirWatcherData
{
    int type = E_TYPE_NONE;
	int     dwAction;
	std::wstring filepath;
	std::wstring watcherpath;
	DirWatcherData() :dwAction(0), filepath(L""), watcherpath(L""){}
};

class DirWatcher  
{
	static void WatchProc(LPVOID pParam);
	static void NotifyProc(LPVOID pParam);
public:
	virtual void NotifyChange(DWORD dwAction, LPCWSTR pfilepath);
	
	void StopWatch();
	void AddWatch(LPCWSTR pdir, int mode);
	bool isRuning();

	DirWatcher(IChangeNotify* pChangeNotify);
	virtual ~DirWatcher();

private:
	void getLongPathName(std::wstring& pathfilename);
	DirWatcher();

	void AddChangeData(const DirWatcherData &changedata);
	void getChangeInfo(std::vector<DirWatcherData> &changes);


private:
	IChangeNotify* m_pChangeNotify;
	watch::DirectoryChanges m_watcherObj;
	std::vector<DirWatcherData> m_changes;
	CsLock m_lock;
	bool m_bRuning;
	HANDLE m_hTerminateEvent;
	wchar_t m_lastfilepath[512];
	wchar_t m_outputstr[512];
};

#endif /* _DIRWATCHER_H_ */
